package step01.model;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import step01.model.domain.JoinTestBean;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class JoinTestDao
{
	static Logger log = Logger.getLogger("JoinTestDao.class");
	private static SqlMapClient sqlMapper;
	
	static
	{
		try
		{
			Reader reader = Resources.getResourceAsReader("step01/model/SqlMapConfig.xml");
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close(); 
	    }
		catch (IOException e)
		{
			  throw new RuntimeException("xml문서 read해서 SqlMapClient객체에 저장시 에러" + e,  e);
	    }
	}
	  

	public static List selectAccountByIdDynamic(List ids) throws SQLException
	{
		return (List)sqlMapper.queryForList("joinTest.dynamicQueryById", ids);
	}
	  
	public static void main(String [] a)
	{
		try
		{		
			ArrayList ids = new ArrayList();			
			ids.add("one");
			ids.add("two");
			ids.add("5");
			
			List<JoinTestBean> data = selectAccountByIdDynamic(ids);
			
			for(JoinTestBean bean : data)
				System.out.println(bean);
		} 
		catch (SQLException e)
		{			
			e.printStackTrace();
		}
	}
}



